<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="Responsive Admin Dashboard Template">
        <meta name="keywords" content="admin,dashboard">
        <meta name="author" content="skcats">
		<title></title>
        <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all" />
        <link th:href="@{/assets/plugins/bootstrap/css/bootstrap.min.css}" rel="stylesheet">
        <link th:href="@{/assets/plugins/font-awesome/css/font-awesome.min.css}" rel="stylesheet">
        <link th:href="@{/assets/css/custom.css}" rel="stylesheet">
        <script th:src="@{/assets/plugins/jquery/jquery-3.1.0.min.js}"></script>
        <script th:src="@{/layui/layui.js}"></script>
	</head>
	<style>
    .utable .layui-laypage .layui-laypage-curr .layui-laypage-em {
            background-color: #1E9FFF;
    }
    .layui-table-page {
            text-align: center;
    }
    .layui-table {
        text-align: center;
        margin-top: -10px;
    }
    .layui-table-view thead th {
        text-align: center;
        font-weight: bold;
    }
    .layui-table-view tbody td {
        text-align: center;
    }
    ::-webkit-scrollbar {display:none}/*隐藏横向滚动条但可以滚动*/
	</style>
<body>
<!--数据表格样式及附件-->
    <script id="toolbarDemo" type="text/html">
        <div class="layui-btn-container">
            <button onclick="add()" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe624;</i>员工入职</button>
            <button class="layui-btn layui-btn-sm" lay-event="word"><i class="layui-icon">&#xe65e;</i>工作经历</button>
            <button class="layui-btn layui-btn-sm" lay-event="education"><i class="layui-icon">&#xe705;</i>教育背景</button>
            <button class="layui-btn layui-btn-sm" lay-event="relation"><i class="layui-icon">&#xe613;</i>家庭关系信息</button>
            <button class="layui-btn layui-btn-sm" lay-event="assess"><i class="layui-icon">&#xe6b2;</i>员工考核</button>
            <button class="layui-btn layui-btn-sm" lay-event="voucher"><i class="layui-icon">&#xe660;</i>证件上传</button>
        </div>
    </script>
<!--表内功能-->
    <script id="bar" type="text/html">
    {{#  if(d.status == 1){ }}
    <a id="ann" class="layui-btn layui-btn-warm layui-btn-xs" lay-event="no">
        <i class="layui-icon">&#xe642;</i>禁用
    </a>
    {{# }if(d.status == 2) { }}
    <a class="layui-btn layui-btn-xs" lay-event="yes">
        <i class="layui-icon">&#xe642;</i>启用
    </a>
    {{#  } }}
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">
        <i class="layui-icon">&#xe6b2;</i>编辑
    </a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="reset">
        <i class="layui-icon">&#xe669;</i>重置密码
    </a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">
        <i class="layui-icon">&#xe640;</i>删除
    </a>
	</script>

<!--搜索狂-->
<form class="layui-form">
    <div class="layui-inline">
        <label class="layui-form-label" style="width: 100px">员工姓名：</label>
        <div class="layui-input-inline">
            <input id="emp_name" style="width: 150px" name="emp_name" placeholder="员工姓名" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-inline">
        <label class="layui-form-label">部门</label>
        <div class="layui-input-block">
            <select id="dep_id" name="dep_id" style="height: 35px;width: 120px;" lay-filter="mySelect">
                <option value="">请选择部门</option>
                <option th:each="e:${deps}" th:value="${e.depid}" th:text="${e.depname}">张先生</option>
            </select>
        </div>
    </div>

    <div class="layui-inline">
        <label class="layui-form-label">职位</label>
        <div class="layui-input-block">
            <select id="post_Id" name="post_Id" style="height: 35px;width: 120px;" lay-filter="mySelect">
                <option value="">请选择职位</option>
                <option th:each="e:${posts}" th:value="${e.pos_Id}" th:text="${e.pos_Name}">张先生</option>
            </select>
        </div>
    </div>

    <div class="layui-inline">
        <div class="layui-input-block" style="margin-left: 30px">
            <button id="ck" type="button" class="btn btn-info btn-addon"><i class="fa fa-spin fa-refresh"></i> 查找</button>
        </div>
    </div>
</form>

<div class="utable">
    <table class="layui-table" id="demo" lay-filter="demo"></table>
</div>

</body>
<script type="text/javascript" th:inline="none">
    //点击添加iframe窗方法
    function add(){
        //iframe窗
        layer.open({
            type: 2,
            title: '员工入职',
            maxmin: true, //开启最大化最小化按钮
            area: ['1000px', '500px'],
            content: ['/emp/toadd']//这是链接你的页面地址 url
        });
    }

    layui.use('table', function () {
        var table = layui.table;

        //方法渲染
        table.render({
            elem: '#demo'
            ,id: 'tab'
            ,height: 535
            ,width: 1250
            ,url: '/emp/empdata' //数据接口
            ,page: true //开启分页
            ,toolbar: '#toolbarDemo'
            ,cols: [[ //表头
                {type: 'radio', title: '选择', fixed: 'left'}
                ,{field: 'emp_id', title: '编号', width:80, sort: true}
                ,{field: 'emp_name', title: '用户名', width:120}
                ,{field: 'emp_sex', title: '性别', width:60}
                ,{field: 'depname', title: '部门', width:100}
                ,{field: 'postname', title: '职务', width:100}
                ,{field: 'phone', title: '电话', width: 120}
                ,{field: 'education', title: '学历', width:60}
                ,{field: 'address', title: '家庭地址', width: 180}
                ,{field: 'status', title: '状态', width: 60, templet: aaa}
                ,{field: 'married', title: '婚姻状况', width:90}
                ,{field: 'nation', title: '籍贯', width:60}
                ,{fixed: 'right', title:'操作', toolbar: '#bar', width:310}
            ]]
        });

        // //模糊
        $("#ck").on('click',function(){
            var emp_name=$("#emp_name").val();
            var dep_id=$("#dep_id").val();
            var post_Id=$("#post_Id").val();
            table.reload('tab', {
                where: { //设定异步数据接口的额外参数，任意设
                    emp_name: emp_name,
                    dep_id:dep_id,
                    post_Id:post_Id,
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //头工具栏事件
        table.on('toolbar(demo)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            var data = checkStatus.data;
            var id = $.map(data,function(d){return d.emp_id;});//获取选中数据的id
            if (data.length === 0 && obj.event != 'LAYTABLE_COLS' && obj.event != 'LAYTABLE_EXPORT' && obj.event != 'LAYTABLE_PRINT'){
                layer.msg(JSON.stringify("未选择用户!"))
            }else if (obj.event === "word"){
                document.location.href="/option/towork?id="+id;
            }else if (obj.event === "education"){
                document.location.href="/option/toeducation?id="+id;
            } else if (obj.event === "relation"){
                document.location.href="/option/tolink?id="+id;
            }else if (obj.event === "assess"){
                document.location.href="/option/toassess?id="+id;
            }else if (obj.event === "voucher"){
                document.location.href="/option/tovoucher?id="+id;
            }
        });

        //监听行工具事件
        table.on('tool(demo)', function (obj) {
            var data = obj.data;//获取数据
            if (obj.event === 'del') {//删除
                layer.confirm('真的删除么?', function (index) {
                    obj.del();
                    layer.close(index);
                    $.ajax({
                        url: '/emp/del',
                        type: 'post',
                        data: {
                            id:data.emp_id
                        },
                        dataType: 'json',
                        success:function(data){
                            layer.msg(JSON.stringify("删除成功"));
                        },
                    })
                });
            } else if (obj.event == "yes") {//禁用
                $.ajax({
                    url: '/emp/set',
                    type: 'post',
                    data: {
                        emp_id:data.emp_id
                        ,status:data.status
                    },
                    dataType: 'json',
                    success : function(data) {
                        if (data){
                            //执行重载
                            $('.layui-laypage-btn').click();
                            //document.location.href="/skip/emplist";
                        }
                    }
                })
            } else if(obj.event === 'no'){//启用
                    $.ajax({
                        url: '/emp/set',
                        type: 'post',
                        data: {
                            emp_id:data.emp_id
                            ,status:data.status
                        },
                        dataType: 'json',
                        success : function(data) {
                            if (data){
                                //执行重载
                                $('.layui-laypage-btn').click();
                                //document.location.href="/skip/emplist";
                            }
                        }
                    })
            }else if (obj.event === 'edit'){//编辑
                layer.open({
                    type: 2,
                    title: '员工编辑',
                    maxmin: true, //开启最大化最小化按钮
                    area: ['1000px', '500px'],
                    content: ['/emp/toedit?emp_id='+data.emp_id]//这是链接你的页面地址 url
                });
            }
            else if (obj.event === 'reset'){//重置密码
                layer.confirm('确认重置密码吗?', function (index) {
                    $.ajax({
                        url: '/emp/reset',
                        type: 'post',
                        data: {
                            emp_id: data.emp_id
                            , password: data.password
                        },
                        dataType: 'json',
                        success: function (data) {
                            if (data) {
                                layer.msg(JSON.stringify("重置密码成功!"))
                                //执行重载
                                $('.layui-laypage-btn').click();
                                //table.reload('tab');
                            } else {
                                layer.msg(JSON.stringify("已是最初密码!"))
                            }
                        }
                    })
                })
            }
        })

        //启用禁用
        function aaa(data){
            var status = data.status;
            var btns = "";
            if (status == 1) {
                return"启用";
            }
            if (status == 2) {
                btns += '<span style="color:#ed2a4a">禁用</span>';
            }
            return btns;
        }
    });
</script>
</html>